package com.example.exp_3_javaweb;

import javax.servlet.ServletContext;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

@WebServlet("/receiveservlet2")
public class ReceiveServlet2 extends HttpServlet {
    @Override
    public void doGet(HttpServletRequest request, HttpServletResponse response) {
        response.setCharacterEncoding("utf-8");
        Student stu1 = (Student) request.getAttribute("student");
        //
        if (stu1==null){
            System.out.println("请求作用域中数据丢失了");
        }else{
            System.out.println("请求作用域中学生姓名:"+stu1.getName());
        }
        //
        if (stu1==null){
            System.out.println("会话作用域中数据丢失了");
        }else{
            HttpSession session = request.getSession();
            Student stu2 = (Student)session.getAttribute("Studenet");
            System.out.println("会话作用域中学生姓名:"+stu2.getName());
        }
        //
        if (stu1==null){
            System.out.println("应用作用域中数据丢失了");
        }else{
            ServletContext servletContext = request.getServletContext();
            Student stu3 = (Student)servletContext.getAttribute("Student");
            System.out.println("应用作用域中学生姓名:"+stu3.getName());
        }
    }
}
